package com.py.androidUtils.UI;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.py.androidUtils.base.BaseActivity;
import com.py.androidUtils.utils.ToastUtil;
import com.py.androidUtils.view.ClearableEditText;
import com.readyidu.app.R;

/**
 * @说明 群名称
 * @作者 LY
 * @文件 GroupNameActivity.java
 * @时间 2015年7月22日 下午2:19:45
 */
public class GroupNameActivity extends BaseActivity {
	private ClearableEditText name;
	private TextView nameSize;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_group_name);
		name = (ClearableEditText) this.findViewById(R.id.name);
		nameSize = (TextView) this.findViewById(R.id.nameSize);
		getTitleActionBar().setImgLeft(R.drawable.icon_back, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finishactivity(GroupNameActivity.this);
			}
		});
		getTitleActionBar().setTitleBar("群聊名称");
		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
			name.setText(bundle.getString("name"));
		}

		nameSize.setText(name.length() + "/20");

		getTitleActionBar().setTvRight1("确定", new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (name.getText().toString().trim().length() > 0) {
					Intent intent = getIntent();
					intent.putExtra("name", name.getText().toString());
					setResult(RESULT_OK, intent);
					finishactivity(GroupNameActivity.this);
				} else {
					ToastUtil.showToast(getApplicationContext(), "请输入群聊名称");
				}
			}
		});

		name.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				nameSize.setText(s.toString().trim().length() + "/20");
			}
		});
	}
}
